local localCtrl = UIManager.Controller(UIManager.ControllerName.FirstPanel, UIManager.ViewName.FirstPanel)

-- ui bind function implementation

local function playAudioButtonClick()
    AudioManager.PlaySound("BGM_Field01", 1)
end

local function openSecondPanel()
    UIManager.openController(UIManager.ControllerName.SecondPanel)
end

local function onSceneLoadStart()
    --UIManager.openController(UIManager.ControllerName.Loading)
    Debug.Log("loading scene start")
end

local function onSceneLoadUpdate(p)
    --    Event.dispatch(Event.LOADING_UPDATE, p)
    Debug.Log(p)
end

local function onSceneLoadComplete()
    Debug.Log("loading scene complete")
end

local function onLoadError(errorMsg)
    Debug.Log("loading scene error!!!!")
end

local function loadScene()
    CS.Kylin.SceneLoader.Instance:LoadScene("New Scene", true, onSceneLoadStart, onSceneLoadUpdate, onSceneLoadComplete, onLoadError)
end

local function asyncResultFunc(res)
    if res ~= nil then 
        GameObject.Find('Canvas')
        local go = GameObject.Instantiate(res)
        go.transform:SetParent(GameObject.Find('Canvas').transform, false)
    end
end

local function asyncLoadTest() 
    CS.Kylin.ResourceLoader.LoadAssetAsync("Prefab/Other/RawImage", asyncResultFunc)
end

local function onStopAudioClick() 
    localCtrl:destroy()
end

function localCtrl:onCreat(data)
    view = localCtrl.View

    -- 绑定view的控件
    view.PlayAudioButton.onClick:AddListener(playAudioButtonClick)
    view.SencondPanelButton.onClick:AddListener(openSecondPanel)
    view.LoadSceneButton.onClick:AddListener(loadScene)
    view.AsyncLoadButton.onClick:AddListener(asyncLoadTest)
    view.AudioStopButton.onClick:AddListener(onStopAudioClick)

    Debug.Log("onCreate FirstPanel controller")
end

function localCtrl:onOpen(data)
    Debug.Log("onOpen FirstPanel controller")
end

function localCtrl:onInteractive(active)
end

function localCtrl:onDestroy()

end